<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/27
 * Time: 18:20
 */

namespace App\Services;


class Behavior
{
    /**
     * @param int $uid  用户id
     * @param int $media_id  视频id
     * @param int $action  动作 （0：点赞  1：分享  2：浏览时长）
     * @param int $duration  浏览时长 （仅当action为浏览时长时传该值）
     * @return void
     */
    public static function write($uid = 0, $media_id = 0, $action = 0, $duration = 0)
    {
        $log_file = env('BEHAVIOR_LOG_PATH') . 'behaviors' . date('Ymd') . '.log';
        if (!is_dir(dirname($log_file))) {
            return;
        }

        $time = time();
        $content = "{$uid}\t{$media_id}\t{$action}\t{$duration}\t{$time}\n";
        file_put_contents($log_file, $content, FILE_APPEND);
    }
}